<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改人员信息')" />
    <th:block th:include="include :: select2-css" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
</head>
<body>
    <div class="main-content">
        <form class="form-horizontal m" id="form-user-edit" th:object="${zhmkUser}">
            <input name="userId" th:field="*{userId}" type="hidden">
            <input name="deptId"  type="hidden"  th:field="*{deptId}" id="treeId"/>
            <h4 class="form-header h4">基本信息</h4>
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">用户名称：</label>
                        <div class="col-sm-8">
                            <input id="userName" name="userName" placeholder="请输入用户名称" class="form-control" type="text" maxlength="30" th:field="*{userName}" required>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">归属部门：</label>
                        <div class="col-sm-8">
                            <div class="input-group">
                                <input name="deptName" onclick="selectDeptTree()" id="treeName" type="text" placeholder="请选择归属部门" class="form-control" th:field="*{dept.deptName}">
                                <span class="input-group-addon"><i class="fa fa-search"></i></span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">人员类型：</label>
                        <div class="col-sm-8">
                            <div class="input-group">
                                <select name="userType" class="form-control m-b">
                                    <option value="00" th:selected="*{userType == '00'}">常驻</option>
                                    <option value="01" th:selected="*{userType == '01'}">临时</option>
                                </select>
                                <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 代码生成请选择字典属性</span>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">联系电话：</label>
                        <div class="col-sm-8">
                            <div class="input-group">
                                <input id="phonenumber" name="phonenumber" placeholder="请输入联系电话" class="form-control" type="text" maxlength="11" th:field="*{phonenumber}">
                                <span class="input-group-addon"><i class="fa fa-mobile"></i></span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">人员性别：</label>
                        <div class="col-sm-8">
                            <select name="sex" class="form-control m-b" th:with="type=${@dict.getType('sys_user_sex')}">
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{sex}"></option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">年龄：</label>
                        <div class="col-sm-8">
                            <div class="input-group">
                                <input id="age" name="age" placeholder="请输入年龄" class="form-control" type="text" maxlength="3" th:field="*{age}">
                                <span class="input-group-addon"></span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">人员状态：</label>
                        <div class="col-sm-8">
                            <select name="userStatus" class="form-control m-b" th:with="type=${@dict.getType('zhmk_user_status')}">
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{userStatus}"></option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-xs-4 control-label">岗位：</label>
                        <div class="col-xs-8">
                            <select id="post" class="form-control select2-multiple" multiple>
                                <option th:each="post:${posts}" th:value="${post.postId}" th:text="${post.postName}" th:selected="${post.flag}" th:disabled="${post.status == '1'}"></option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-12">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">人员头像：</label>
                        <div class="col-sm-4 fileinput fileinput-new" data-provides="fileinput">
                            <input name="avatar" id="pic" class="form-control" type="hidden" th:value="*{avatar}">
                            <div>
                                <span class="btn btn-white btn-file">
                                    <span class="fileinput-new">选择图片</span>
                                    <input type="file" id="abc">
                                </span>
                            </div>
                            <div id="showpic" class="fileinput-preview fileinput-exists thumbnail" style="max-width: 200px; max-height: 150px;display: none"></div>
                            <div class="fileinput-new thumbnail" th:style="*{avatar==null || avatar==''}?'display:none':'max-width: 200px; max-height: 150px;display:block'"><a id="url"><img style="max-height: 140px;" th:src="*{avatar}"></a></div>
                        </div>
                    </div>
                </div>
            </div>
            <h4 class="form-header h4">其他信息</h4>
            <div class="row">
                <div class="col-sm-12">
                    <div class="form-group">
                        <label class="col-xs-2 control-label">备注：</label>
                        <div class="col-xs-10">
                            <textarea name="remark" maxlength="500" class="form-control" rows="3">[[*{remark}]]</textarea>
                        </div>
                    </div>
                </div>
            </div>

           <!-- <div class="form-group">
                <label class="col-sm-3 control-label">部门ID：</label>
                <div class="col-sm-8">
                    <input name="deptId" th:field="*{deptId}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">姓名：</label>
                <div class="col-sm-8">
                    <input name="userName" th:field="*{userName}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">人员类型：</label>
                <div class="col-sm-8">
                    <select name="userType" class="form-control m-b">
                        <option value="">所有</option>
                    </select>
                    <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 代码生成请选择字典属性</span>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">联系电话：</label>
                <div class="col-sm-8">
                    <input name="phonenumber" th:field="*{phonenumber}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">性别：</label>
                <div class="col-sm-8">
                    <select name="sex" class="form-control m-b" th:with="type=${@dict.getType('sys_user_sex')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{sex}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">年龄：</label>
                <div class="col-sm-8">
                    <input name="age" th:field="*{age}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">头像路径：</label>
                <div class="col-sm-8">
                    <input name="avatar" th:field="*{avatar}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">人员状态：</label>
                <div class="col-sm-8">
                    <div class="radio-box">
                        <input type="radio" name="userStatus" value="">
                        <label th:for="userStatus" th:text="未知"></label>
                    </div>
                    <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 代码生成请选择字典属性</span>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">临时人员最后使用时间：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <input name="pwdUpdateDate" th:value="${#dates.format(zhmkUser.pwdUpdateDate, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <textarea name="remark" class="form-control">[[*{remark}]]</textarea>
                </div>
            </div>-->
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: select2-js" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: jasny-bootstrap-js" />
    <script th:inline="javascript">
        var prefix = ctx + "zhmk/user";
        //上传图片
        $("#abc").change(function(){
            if ($('#abc')[0].files[0] == null) {
                $.modal.alertWarning("请先选择文件路径");
                $("#showpic").hide();
                $("#url").parent().show();
            }else{
                var data = new FormData();
                var file = $("#abc")[0].files[0];
                if (/^image\/\w+$/.test(file.type)) {
                    data.append("file", file);
                    $.ajax({
                        type:"POST",
                        url:ctx + "common/upload",
                        data:data,
                        cache:false,
                        contentType: false,
                        processData: false,
                        dataType:'json',
                        success: function(reuslt){
                            //alert(JSON.stringify(reuslt));
                            if(reuslt.code == web_status.SUCCESS){
                                $("#url img").attr("src",reuslt.fileName);
                                $("#pic").val(reuslt.fileName);
                                $("#showpic").show();
                                $("#url").parent().hide();
                            }
                        },
                        error:function(error){
                            alert("图片上传失败。");
                            $("#showpic").hide();
                        }
                    })
                } else {
                    $.modal.alertWarning('请选择一个图片文件。');
                    $("#showpic").hide();
                }
            }
        })
        $("#form-user-edit").validate({
            onkeyup: false,
            rules:{
                phonenumber:{
                    isPhone:true,
                    remote: {
                        url: prefix + "/checkPhoneUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                            "userId": function() {
                                return $("#userId").val();
                            },
                            "phonenumber": function() {
                                return $.common.trim($("#phonenumber").val());
                            }
                        },
                        dataFilter: function (data, type) {
                            return $.validate.unique(data);
                        }
                    }
                },
            },
            messages: {
                "phonenumber":{
                    remote: "手机号码已经存在"
                }
            },
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                var data = $("#form-user-edit").serializeArray();
                var postIds = $.form.selectSelects("post");
                data.push({"name": "postIds", "value": postIds});
                $.operate.save(prefix + "/edit", data);
            }
        }

        /* 用户管理-修改-选择部门树 */
        function selectDeptTree() {
            var deptId = $.common.isEmpty($("#treeId").val()) ? "100" : $("#treeId").val();
            var url = ctx + "zhmk/dept/selectDeptTree/" + deptId;
            var options = {
                title: '选择部门',
                width: "380",
                url: url,
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }

        function doSubmit(index, layero){
            var tree = layero.find("iframe")[0].contentWindow.$._tree;
            var body = layer.getChildFrame('body', index);
            $("#treeId").val(body.find('#treeId').val());
            $("#treeName").val(body.find('#treeName').val());
            layer.close(index);
        }

        $(function() {
            $('#post').select2({
                placeholder: "请选择岗位",
                allowClear: true
            });
        })

    </script>
    <script th:inline="javascript">
        /*var prefix = ctx + "zhmk/user";
        $("#form-user-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-user-edit').serialize());
            }
        }

        $("input[name='pwdUpdateDate']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });*/
    </script>
</body>
</html>